package com.lagou.dubbo.web.controller;

import com.lagou.api.HelloService;
import com.lagou.dubbo.web.util.IpUtil;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class TestController {


    @Autowired
    private HelloService helloService;


    @GetMapping("/dubbo-test")
    public String test(HttpServletRequest request){

        RpcContext.getContext().setAttachment("clientIp", IpUtil.getClientIpv4(request));
        RpcContext.getContext().setAttachment("browser", IpUtil.getBrowser(request));
        String res = helloService.sayHello("hello");
        return res;
    }
}
